//
//  LoginVC.swift
//  Pods
//
//  Created by HongPu on 2015/8/5.
//
//

public class LoadingViewController: UIViewController
{
    private var arrayRequest = Array<NetWorkRequest>()
    
    override public func viewDidDisappear(animated: Bool)
    {
        super.viewDidDisappear(animated)
        self.clean()
    }
    
    deinit
    {
        self.clean()
    }
    
    private func clean()
    {
        // TODO: 判断是否在VC栈中
        arrayRequest.filter{ (req) in
            NetWorkManager.cancelRequest(req)
            return false
        }
    }
    
    public func loading(bussiness: String, data: NetWorkParameterData, donefunc: (Result<NetWorkResultModel>) -> ())
    {
        self.startLoadingAnmiation()
        
        let req = NetWorkManager.requestGET(bussinessUrl: bussiness, data: data, donefunc: { (result) in
            
            // FIXME: 如何从arrRequest中去除
            self.endLoadingAnmiation()
            donefunc(result)
        })
        
        arrayRequest.append(req)
    }
    
    
    private func startLoadingAnmiation()
    {
        print("start")
    }
    
    private func endLoadingAnmiation()
    {
        print("end")
    }
}
